package com.pagoda.nerp.web.repositories;

import com.pagoda.nerp.web.entities.HRUnit;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Set;

@Transactional
public interface HRUnitDao extends JpaRepository<HRUnit,String> {
    public List<HRUnit> findByParentnm(String parentnm) ;

    @Query(value = "select * from hrunit hrtable WHERE hrtable.canonicalcode LIKE ?1% order by length(hrtable.canonicalcode),hrtable.canonicalcode",nativeQuery = true)
    public List<HRUnit> findData(String rootcode);

    @Query(value = "SELECT * from hrunit hrtable where orgcode = ?1 limit 1",nativeQuery = true)
    public HRUnit findByOrgcode(String orgcode);

    @Query(value = "SELECT orgcode from hrunit where hrunit.canonicalcode like %?1%",nativeQuery = true)
    public Set<String> findByCanonicalcodeLike(String unitid);

}
